/* This is the Colour class, this is where all attributes for the array of colors are 
 assigned and compared to be displayed.*/

/* Author: Mark Mckillion, Chris Mowbray
 * Date: 17/04/2012
 * Version 1.0.*/
package assignment4;

import java.awt.*;

@SuppressWarnings("rawtypes")
public class Colour implements Comparable
{   //create the colors of the rainbow that will be used within the array.
    protected final static Color red = new Color(225,0,0);
    protected final static Color orange = new Color(255,200,0);
    protected final static Color yellow = new Color(255,255,0);
    protected final static Color green = new Color(0,225,0);
    protected final static Color blue = new Color(0,0,255);
    protected final static Color indigo = new Color(75,0,130);
    protected final static Color violet = new Color(238,130,238);
    
    //create an array and set it to 0 initially.
    protected static Color [] colors = new Color[0];
    
    //create an instance of the class which will be used within the compare to method.
    protected static Colour colour = new Colour();
    
    //create ints that will be used to control the object order and values.
    protected static int num, rainbowValue, compareNum;
    
    //a method that will be used to create an array, will accept an int to determain the
    //array size.
    public void createArray(int n)
    {   //make the array size equal the number entered.
        colors = new Color[n];
        
        //use a for loop to create assign colors to the array.
        for(int i = 0; i < colors.length; i++)
        {   //create an int to make the array objects random.
            num = (int)(Math.random()*100);
            if(num <= 14)
            {   colors[i] = red;
            }   else if(num <= 28)
                {   colors[i] = orange;
                }   else if(num <= 42)
                    {   colors[i] = yellow;
                    }   else if(num <= 56)
                        {   colors[i] = green;
                        }   else if(num <= 70)
                            {   colors[i] = blue;
                            }   else if(num <= 84)
                                {   colors[i] = indigo;
                                }   else if(num >= 85)
                                    {   colors[i] = violet;
                                    }
        }
    }
    
    //create a method which will determain where the color appears in the rainbow.
    public int getRainbowColourNumber(Color c)
    {   //method uses the parameter value to assign an int to each colour.
        if(c == red)
        {   rainbowValue = 1;
        }   if(c == orange)
            {   rainbowValue = 2;
            }   if(c == yellow)
                {   rainbowValue = 3;
                }   if(c == green)
                    {   rainbowValue = 4;
                    }   if(c == blue)
                        {   rainbowValue = 5;
                        }   if(c == violet)
                            {   rainbowValue = 6;
                            }   if(c == indigo)
                                {   rainbowValue = 7;
                                }
        //return the value.
        return rainbowValue;
    }
    
    //create a method which will determain how light the colour is.
    public int getLightColourNumber(Color c)
    {   //method uses the parameter value to assign an int to each colour.
        if(c == yellow)
        {   rainbowValue = 1;
        }   if(c == orange)
            {   rainbowValue = 2;
            }   if(c == violet)
                {   rainbowValue = 3;
                }   if(c == green)
                    {   rainbowValue = 4;
                    }   if(c == blue)
                        {   rainbowValue = 5;
                        }   if(c == red)
                            {   rainbowValue = 6;
                            }   if(c == indigo)
                                {   rainbowValue = 7;
                                }
        //return the value.
        return rainbowValue;
    }
    
    //create a method which will determain how dark the colour is.
    public int getDarkColourNumber(Color c)
    {   //method uses the parameter value to assign an int to each colour.
        if(c == indigo)
        {   rainbowValue = 1;
        }   if(c == red)
            {   rainbowValue = 2;
            }   if(c == blue)
                {   rainbowValue = 3;
                }   if(c == green)
                    {   rainbowValue = 4;
                    }   if(c == violet)
                        {   rainbowValue = 5;
                        }   if(c == orange)
                            {   rainbowValue = 6;
                            }   if(c == yellow)
                                {   rainbowValue = 7;
                                }
        //return the value.
        return rainbowValue;
    }
    
    //create a compareTo method that will compare the colors that are entered.
    public int compareTo(Color color1, Color color2)
    {   //create to integers that will be used to compare the color numbers.
        int num1, num2;
        
        if(ControlPanel.jComboBox4.getSelectedItem().equals("Order of the Rainbow"))
        {   //if order of the rainbow is chosen get the values for each colour
            num1 = colour.getRainbowColourNumber(color1);
            num2 = colour.getRainbowColourNumber(color2);
            
            //compare the colours and use integers to determain how the colors relate to each other.
            if(num1 == num2)
            {   compareNum = 0;
            }   if(num1 < num2)
                {   compareNum = -1;
                }   if(num1 > num2)
                    {   compareNum = 1;
                    }
        }
        
        if(ControlPanel.jComboBox4.getSelectedItem().equals("Light to Dark"))
        {   //if light to dark is chosen get the values for each colour
            num1 = colour.getLightColourNumber(color1);
            num2 = colour.getLightColourNumber(color2);
            
            //compare the colours and use integers to determain how the colors relate to each other.
            if(num1 == num2)
            {   compareNum = 0;
            }   if(num1 < num2)
                {   compareNum = -1;
                }   if(num1 > num2)
                    {   compareNum = 1;
                    }
        }
                
        if(ControlPanel.jComboBox4.getSelectedItem().equals("Dark to Light"))
        {   //if dark to light is chosen get the values for each colour
            num1 = colour.getDarkColourNumber(color1);
            num2 = colour.getDarkColourNumber(color2);
            
            //compare the colours and use integers to determain how the colors relate to each other.
            if(num1 == num2)
            {   compareNum = 0;
            }   if(num1 < num2)
                {   compareNum = -1;
                }   if(num1 > num2)
                    {   compareNum = 1;
                    }
        }
        //return the comparsion value.
        return compareNum;
    }

    //override all abstract methods.
    @Override
    public int compareTo(Object o) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}   //End of Colour class.